﻿using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using FileDuplicateRemover.Core;

namespace FileDuplicateRemover.Test.WinForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            DirectoryEntity de = null;
            using (EntityTreeBuilder eb = new EntityTreeBuilder("c:\\FDR_TEST"))
            {
                de = eb.Create();
            }

            DuplicateEntityDescriptionList duplicateEntityList = new DuplicateEntityDescriptionList();
            EntityTreeWalker ec = new EntityTreeWalker();

            ec.Walk(de, (be) =>
            {
                duplicateEntityList.Add(be);
                return false;
            });

            IEnumerable<DuplicateEntityDescription> sortedList = duplicateEntityList.OrderBy(i => i.SomeEntity.Length);            

            foreach (DuplicateEntityDescription ded in sortedList)
            {
                ListViewGroup group = new ListViewGroup();
                group.Header = ded.SomeEntity.FullName;
                listView1.Groups.Add(group);

                foreach (BaseEntity be in ded)
                {
                    ListViewItem item = new ListViewItem(be.FullName);

                    listView1.Items.Add(item);
                    item.Group = group;
                }

            }
        }
    }
}
